<a>/*****************************************************
 *
 *    This file is auto generated
 *
 *    SHA1: @ViewBag.Checksum
 *
 *****************************************************/
@{ SAP.BusinessOne.Mackinac.Generator.Model.MBag bag = ViewBag; }
#include "mackinac.h"
#include "Mediator.h"

#define TARGET_ASSEMBLY L"@bag.AssemblyName"
#define TYPE_PROXY L"SAP.BusinessOne.WebBridge.Framework.Proxy"
@foreach (var ns in bag.Namespaces)
{ 
    foreach (var clz in ns)
    {
<a>#define TYPE_@clz.TechnicalName L"@clz.FullName"</a>
    }
}

@foreach (var ns in bag.Namespaces)
{
    @ns.Key.BeginTag
    foreach (var clz in ns)
    {
    <a>
    /*
     * @clz.Name
     */
    unique_ptr<@clz.Name> @clz.Name::s_instance;
    @clz.Name::@clz.Name () : m_hash(0), m_mediator(nullptr)
    {
        Mediator* mediator = new Mediator(TARGET_ASSEMBLY, TYPE_PROXY, TYPE_@clz.TechnicalName);
        m_hash = mediator->create();
        m_mediator = mediator;
    }
    @clz.Name::~@clz.Name ()
    {
        if(m_mediator)
        {
            delete m_mediator;
            m_mediator = nullptr;
        }
    }
    @clz.Name& @clz.Name::instance()
    {
        if(!s_instance)
        {
            s_instance.reset(new @clz.Name ());
        }
        return *s_instance;
    }
    @foreach (var method in clz.Methods)
    {
    <a>
    @method.ReturnType @clz.Name::@method.Name (@method.InputTypes.ToString()) const
    {
        Args args;
        Mediator* mediator = static_cast<Mediator*>(m_mediator);

        args.put(mediator->getType())
            .put(m_hash)
            .put(wstring(L"@method.TechnicalName"))
            @foreach (var ip in method.InputTypes)
            {
            <a>.put(@ip.Name)</a>
            }        ;
        mediator->call(args);

        bool success;
        @if(!method.IsVoidReturnType)
        {
        <a>@method.ReturnType ret = @method.ReturnTypeDefaultValue;</a>
        }

        args.get(success);
        if(!success)
        {
            wstring err;
            args.extend().get(err);
        }
        else
        {
            @if(method.ReturnType == "wstring")
            {
            <a>args.extend().get(ret);</a>
            }
            else if(!method.IsVoidReturnType)
            {
            <a>args.get(ret);</a>
            }
        }

        @if(!method.IsVoidReturnType)
        {
        <a>return ret;</a>
        }
    }
    </a>
    }
    </a>
    }
    @ns.Key.EndTag
}
</a>